package com.fox.stock.control;


import com.fox.stock.pojo.domain.*;
import com.fox.stock.service.impl.StockServiceImpl;
import com.fox.stock.pojo.vo.resq.PageResult;
import com.fox.stock.pojo.vo.resq.R;
import io.swagger.annotations.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 股票相关的接口处理
 */
@Api(value = "/api/quot", tags = {"股票相关的接口处理"})
@RestController
@RequestMapping("/api/quot")
public class StockController {

    @Autowired
    StockServiceImpl stockServiceImpl;

    /**
     * 获取最近时间的国内大盘数据
     * @return
     */
    @ApiOperation(value = "获取最近时间的大盘数据", notes = "获取最近时间的大盘数据", httpMethod = "GET")
    @GetMapping("/index/all")
    public R<List<InnerMarketDomain>> getInnerMarketInfo(){
        return stockServiceImpl.getInnerMarketInfo();
    }

    /**
     * 获取最近时间的国外大盘数据
     * @return
     */
    @ApiOperation(value = "获取最近时间的国外大盘数据", notes = "获取最近时间的国外大盘数据", httpMethod = "GET")
    @GetMapping("/external/index")
    public R<List<OutMarketDomain>> getOutMarketInfo(){
        return stockServiceImpl.getOutMarketInfo();
    }

    /**
     * 获取国内板块指数
     * @return
     */
    @ApiOperation(value = "获取国内板块指数", notes = "获取国内板块指数", httpMethod = "GET")
    @GetMapping("/sector/all")
    public R<List<StockBlockDomain>> getInnerSectorIndexInfo(){
        return stockServiceImpl.getInnerSectorIndexInfo();
    }

    /**
     * 获取涨跌数据
     * @param page
     * @param pageSize
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "page", value = ""),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "")
    })
    @ApiOperation(value = "获取涨跌数据", notes = "获取涨跌数据", httpMethod = "GET")
    @GetMapping("/stock/all")
    public R<PageResult<StockUpdownDomain>> getStockUpDownByPageHlper(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                                                                      @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize){
        return stockServiceImpl.getStockUpDownByPageHlper(page, pageSize);
    }

    /**
     * 获取涨幅榜数据(前四)
     * @return
     */
    @ApiOperation(value = "获取涨幅榜数据(前四)", notes = "获取涨幅榜数据(前四)", httpMethod = "GET")
    @GetMapping("/stock/increase")
    public R<List<StockUpdownDomain>> getStockUpDownList() {
        return stockServiceImpl.getStockUpDownList();
    }

    /**
     * 获取涨跌停数据
     * @return
     */
    @ApiOperation(value = "获取涨跌停", notes = "获取涨跌停", httpMethod = "GET")
    @GetMapping("/stock/updown/count")
    public R<Map<String,List>> getStockUpDownCount() {
        return stockServiceImpl.getStockUpDownCount();
    }

    /**
     * 导出涨幅榜数据
     * @param page
     * @param pageSize
     * @param response
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "page", value = ""),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "")
    })
    @ApiOperation(value = "导出涨幅榜数据", notes = "导出涨幅榜数据", httpMethod = "GET")
    @GetMapping("/stock/export")
    public void StockExport(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                            @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                            HttpServletResponse response){
        stockServiceImpl.StockExport(page, pageSize,response);
    }

    /**
     * 统计A股大盘T日和T-1日成交量对比
     * @return
     */
    @ApiOperation(value = "统计A股大盘T日和T-1日成交量对比", notes = "统计A股大盘T日和T-1日成交量对比", httpMethod = "GET")
    @GetMapping("/stock/tradeAmt")
    public R<Map<String, List>> stockTradeVol4InnerMarket(){
        return stockServiceImpl.stockTradeVol4InnerMarket();
    }

    /**
     * 获取股票涨跌区间信息
     * @return
     */
    @ApiOperation(value = "获取股票涨跌区间信息", notes = "获取股票涨跌区间信息", httpMethod = "GET")
    @GetMapping("/stock/updown")
    public R<Map<String, Object>> getPriceRangeInfo(){
        return stockServiceImpl.getPriceRangeInfo();
    }

    /**
     * 查询个股的分时行情数据
     * @param code 个股编号
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "个股编号", required = true)
    })
    @ApiOperation(value = "查询个股的分时行情数据", notes = "查询个股的分时行情数据", httpMethod = "GET")
    @GetMapping("/stock/screen/time-sharing")
    public R<List<Stock4MinuteDomain>> getStockScreenHourTimeSharing(@RequestParam("code") String code){
        return stockServiceImpl.getStockScreenTimeSharing(code);
    }

    /**
     * 获取个股的日分k线信息
     * @param code 个股编号
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "个股编号", required = true)
    })
    @ApiOperation(value = "获取个股的日分k线信息", notes = "获取个股的日分k线信息", httpMethod = "GET")
    @GetMapping("/stock/screen/dkline")
    public R<List<Stock4EvrDayDomain>> getStockScreenDayTimeSharing(@RequestParam("code") String code){
        return stockServiceImpl.getStockScreenDayTimeSharing(code);
    }

    /**
     * 根据前端提供的个股编号,返回证券代码和名称
     * @param searchStr 个股编号
     * @return 证券代码和名称
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "searchStr", value = "个股编号", required = true)
    })
    @ApiOperation(value = "根据前端提供的个股编号,返回证券代码和名称", notes = "根据前端提供的个股编号,返回证券代码和名称", httpMethod = "GET")
    @GetMapping("stock/search")
    public R<List<Map>> autoSearchByRtCode(@RequestParam(value = "searchStr", required = true) String searchStr){
        return stockServiceImpl.autoSearchByRtCode(searchStr);
    }


    /**
     * 个股主营业务查询接口
     * @param code
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "股票编号", required = true)
    })
    @ApiOperation(value = "查询个股的主营业务数据", notes = "查询个股的主营业务数据", httpMethod = "GET")
    @GetMapping("/stock/describe")
    public R<StockRtInfoDomain> getRtInfoMainWork(@RequestParam("code") String code){
        return stockServiceImpl.getRtInfoMainWork(code);
    }

    /**
     * 统计每周内的股票数据信息
     * @param code
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "股票编号", required = true)
    })
    @ApiOperation(value = "统计每周内的股票数据信息", notes = "统计每周内的股票数据信息", httpMethod = "GET")
    @GetMapping("/stock/screen/weekkline")
    public R<List<WeekKLineByRtInfoDomain>> getWeekKLineInfo(@RequestParam("code") String code){
        return stockServiceImpl.getWeekKLineInfo(code);
    }


    /**
     * 获取个股最新分时行情数据
     * @param code
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "股票编号", required = true)
    })
    @ApiOperation(value = "获取个股最新分时行情数据", notes = "获取个股最新分时行情数据", httpMethod = "GET")
    @GetMapping("/stock/screen/second/detail")
    public R<StockRtDomain> getStockRtDetailInfo(@RequestParam("code") String code){
        return stockServiceImpl.getStockRtDetailInfo(code);
    }


    /**
     * 查询最新交易流水(前十条)
     * @param code
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "股票编号", required = true)
    })
    @ApiOperation(value = "查询最新交易流水(前十条)", notes = "查询最新交易流水(前十条)", httpMethod = "GET")
    @GetMapping("/stock/screen/second")
    public R<List<Map<String,Object>>> getTradeDetailPre10Info(@RequestParam("code") String code){
        return stockServiceImpl.getTradeDetailPre10Info(code);
    }


}
